#ifndef _OLED_H_
#define _OLED_H_

#include <stdbool.h>

// commands SSD1305 controller
#define OLED_SET_COL_HI		0x10
#define OLED_SET_COL_LO		0x00
#define OLED_SET_LINE			0x40
#define OLED_SET_CONTRAST		0x81
#define OLED_SET_BRIGHTNESS  0x82
#define OLED_SET_LOOKUP      0x91
#define OLED_SET_SEG_REMAP0  0xA0
#define OLED_SET_SEG_REMAP1	0xA1
#define OLED_EON_OFF			0xA4
#define OLED_EON_ON			0xA5
#define OLED_DISP_NOR			0xA6
#define OLED_DISP_REV			0xA7
#define OLED_MULTIPLEX       0xA8
#define OLED_MASTER_CONFIG   0xAD
#define OLED_CHARGE_PUMP    	0x8D
#define OLED_PUMP_OFF    		0x10
#define OLED_PUMP_ON     		0x14
#define OLED_DISP_OFF 			0xAE
#define OLED_DISP_ON			0xAF
#define OLED_SET_PAGE			0xB0
#define OLED_SET_SCAN_FLIP	0xC0
#define OLED_SET_SCAN_NOR		0xC8
#define OLED_SET_OFFSET		0xD3
#define OLED_SET_RATIO_OSC	0xD5
#define OLED_SET_AREA_COLOR  0xD8
#define OLED_SET_CHARGE  		0xD9
#define OLED_SET_PADS    		0xDA
#define OLED_SET_VCOM    		0xDB
#define OLED_NOP     			0xE3
#define OLED_SCROLL_RIGHT		0x26
#define OLED_SCROLL_LEFT		0x27
#define OLED_SCROLL_VR	    	0x29
#define OLED_SCROLL_VL			0x2A
#define OLED_SCROLL_OFF		0x2E
#define OLED_SCROLL_ON   		0x2F
#define OLED_SCROLL_ON   		0x2F
#define OLED_VERT_SCROLL_A  	0xA3
#define OLED_MEM_ADDRESSING 	0x20
#define OLED_SET_COL_ADDR		0x21
#define OLED_SET_PAGE_ADDR	0x22

//=================================================
void OLED_Init(void);
void OLED_print_string (const char *ptr);
void OLED_Reflash(void);
void OLED_print_char(char ch);
void OLED_write_fb(uint8_t data);
//void OLED_clr_lines(uint8_t line_mask);
//void OLED_clr_display(void);
void OLED_Write (uint8_t cmd);
void OLED_setBrightness(uint8_t brightness);
bool OLED_is_offscreen(void);
bool OLED_almost_offscreen(void);

#define OLED_OFF()	OLED_Write(OLED_DISP_OFF)
#define OLED_TO_RST() clrbit(PORT_OLED_OUT, PIN_OLED_RST);
#endif
